package Lianxi;

public class Torch {
    private int power;

    /**
     * 打开手电筒
     */
    public Torch() {
        this.power = 30;
    }

    public void on() {
        System.out.println("开启");
        while (true) {
            power -= 10;
            try {
                Thread.sleep(500L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("当前电量为：" + power);
            if (power <= 0) {
                System.out.println("电量耗尽");
                this.off();
                break;
            }
        }
    }
    public void off () {
        System.out.println("关闭");
    }

    public void charging() {
        this.power = 10;
        System.out.println("正在充电中：");
        while (true) {
            power += 10;
            try {
                Thread.sleep(500L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("当前电量为：" + power);
            if (power >= 100) {
                System.out.println("电量已满");
                break;
            }
        }
    }
    public static void main(String[] args){
        Torch gm = new Torch();
        gm.charging();
    }
}
